<template>
	<view class="baseView">
		<u-search
			placeholder="搜索菜品"
			style="align-self: center; margin: 8rpx;"
			v-model="searchValue"
			@custom="jumpToSearch"
			@search="jumpToSearch"
		></u-search>
		<scroll-view scroll-y style="width: 100%;height: 100%; margin-bottom: 100rpx;">
			<view
				class="myCardBox"
				v-for="(item, index) in currentList"
				:key="index"
				v-model="currentList"
				@click="showDetail(item.id, item.name)"
			>
				<u-row :gutter="16">
					<u-col span="2"><u-image :src="item.image" width="100rpx" height="100rpx"></u-image></u-col>
					<u-col span="10">
						<view style="font-weight: bold;">{{ item.name }}</view>
						<u-rate :disabled="true" :current="item.score" min-count="5" :gutter="5"></u-rate>
						<view class="myflexRow">
							<view>人均消费:{{ item.saleQuantity }}</view>
							<view>平均送达时间: {{ item.deliveryTime }}</view>
						</view>
						<view class="myflexRow">
							<view>店家距离:{{ item.distance }}</view>
							<view>三小时销量:{{ item.saleNum3hour }}</view>
						</view>
					</u-col>
				</u-row>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			themeId: 1,
			searchValue: '',
			currentList: [],
			searchList: [],
			mallList: [],
			mockdata: {
				searchValue: null,
				createBy: null,
				createTime: '2021-04-30 12:01:35',
				updateBy: null,
				updateTime: '2021-05-11 15:40:46',
				remark: null,
				params: {},
				id: 3,
				name: '贡茶',
				address: '尖山街131号1-2',
				introduction: '黑石礁奶茶第二名',
				themeId: 2,
				score: 4.8,
				saleQuantity: 3737,
				deliveryTime: 38,
				imgUrl: '/prod-api/profile/upload/image/2021/05/08/a42956a6-6ca5-47a1-8778-c93d8deba365.jpg',
				avgCost: 20.0,
				other: null,
				recommend: 'Y',
				distance: 3700.0,
				saleNum3hour: 66
			}
		};
	},
	methods: {
		getMallList: function() {
			this.$u.get(`/prod-api/api/takeout/seller/list?themeId=${this.themeId}`).then(res => {
				res.rows.forEach(item => {
					let tempUrl = this.$u.http.config.baseUrl.concat(item.imgUrl);
					item.image = tempUrl;
				});
				this.mallList = res.rows;
				this.currentList = this.mallList;
			});
		},
		showDetail: function(id, name) {
			uni.showToast({
				title: `这是${name}`,
				duration: 500,
				success() {
					uni.navigateTo({
						url: `../mallDetail/mallDetail?id=${id}`
					});
				}
			});
		},
		jumpToSearch: function() {
			if (this.searchValue == '') {
				uni.showToast({
					title: '当前搜索值为空',
					duration: 500
				});
			} else {
				uni.navigateTo({
					url: `mallSearchResult/mallSearchResult?content=${this.searchValue}`
				});
			}
		}
	},
	onLoad(option) {
		console.log(option.themeId);
		this.themeId = option.themeId;
		console.log(this.themeId);
		this.getMallList();
	}
};
</script>

<style></style>
